/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.EditPanes.Filter;

import GUI.Components.BTextField;
import GUI.Components.ColorButton;
import GUI.EditPanes.EditTaskPane;
import General.CurrentData;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.Callable;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import other.ColorScaleFilterWithGetters;
import other.Wizard;

/**
 *
 * @author David
 */
public class ColorScaleTaskPane extends EditTaskPane
{

    private BTextField colorDensityField;
    private ColorButton colorButton;
    private JCheckBox multiplyCheckBox, overlayCheckBox;

    public ColorScaleTaskPane(final ColorScaleFilterWithGetters filter)
    {
        colorDensityField = new BTextField("Float", Float.toString(filter.getColorDensity()));
        colorButton = new ColorButton(Wizard.makeColor(filter.getFilterColor()));
        multiplyCheckBox = new JCheckBox("", filter.isMultiply());
        overlayCheckBox = new JCheckBox("", filter.isOverlay());
        multiplyCheckBox.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                {
                    public Void call() throws Exception
                    {
                        filter.setMultiply(multiplyCheckBox.isSelected());
                        return null;
                    }
                });
            }
        });
        overlayCheckBox.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                {
                    public Void call() throws Exception
                    {
                        filter.setOverlay(overlayCheckBox.isSelected());
                        return null;
                    }
                });
            }
        });
        taskPane.add("left", new JLabel("Color:"));
        taskPane.add("tab hfill", colorButton);
        taskPane.add("br left", new JLabel("Color Density:"));
        taskPane.add("tab hfill", colorDensityField);
        taskPane.add("br left", new JLabel("Multiply:"));
        taskPane.add("tab hfill", multiplyCheckBox);
        taskPane.add("br left", new JLabel("Overlay:"));
        taskPane.add("tab hfill", overlayCheckBox);
        taskPane.add("br left", applyButton);
        taskPane.setTitle("Color Scale Filter");
        applyButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                {
                    public Void call() throws Exception
                    {
                        filter.setColorDensity(Float.parseFloat(colorDensityField.getText()));
                        filter.setFilterColor(Wizard.makeColorRGBA(colorButton.getColor()));
                        filter.setMultiply(multiplyCheckBox.isSelected());
                        filter.setOverlay(overlayCheckBox.isSelected());
                        /*because..................................................*/
                        filter.setColorDensity(Float.parseFloat(colorDensityField.getText()));
                        filter.setFilterColor(Wizard.makeColorRGBA(colorButton.getColor()));
                        filter.setMultiply(multiplyCheckBox.isSelected());
                        filter.setOverlay(overlayCheckBox.isSelected());
                        return null;
                    }
                });
            }
        });
        add(taskPane, BorderLayout.CENTER);
    }
}
